public class Stack<T> {
  private T[] stack;
  private int top;
  private static int SIZE = 100;

  Stack(){
    stack = (T[])new Object[SIZE];
    top = 0;
  }

  public void push(T value){
    if(top >= SIZE){
      System.out.println("Stack overflow");
      // throw new Exception("Stack Overflow");
    }
    stack[top] = value;
    top++;
  }

  public T pop() throws Exception {
    if(top <=0){
      throw new Exception("Stack empty");
    } 
    top--;
    return stack[top];
  }

  public T peek() throws Exception {
    if(top <=0){
      throw new Exception("Stack empty");
    } else {
       return stack[top-1];
    }
  }

  public boolean isEmpty(){
    return top == 0;
  }

  public int size(){
    return top;
  }
}